<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Product extends Site {

    function setup() {
        $this->run_modes('trial_invitation', 'detail', 'getALLuser', 'getReportsList', 'getLookup', 'getReportsCommentList', 'getEventList', 'getEventById', 'getMyApplicationList', 'searchProduct', 'getIMoreNews', 'getindexBanner', 'Top5', 'points', 'Campaign', 'test', 'testupload', 'StaruserReport', 'StaruserUser', 'StaruserHiliteuser', 'testBlogCategory', 'fg_product', 'fg_report', 'get_fg_hilite_left_product', 'get_fg_hilite_middle_product', 'fg_new_report', 'fg_hilite_category', 'fg_product_by_category','fg_hilite_user','fg_blog','to_fg_blog');
        $this->start_mode('trial_invitation');
        $this->selfurl = '/productTest.php';
        $this->pagesize = 3;
        parent::setup();
    }

    function cgiapp_prerun($rm = '') {
        $this->Product = getModel('Model_Product');
        $this->Product_application = getModel('Model_ProductApplication');
        $this->MemberApplication = getModel('Model_MemberApplication');
        $this->ProductReports = getModel('Model_ProductReports');
        $this->Lookup = getModel('Model_Lookup');
        $this->ProductReportsComment = getModel('Model_ProductReportsComment');
        $this->Event = getModel('Model_Event');
        $this->IMoreNews = getModel('Model_IMoreNews');
        $this->indexBanner = getModel('Model_indexBanner');
        $this->Top5 = getModel('Model_Top5');
        $this->Points = getModel('Model_Points');
        $this->Campaign = getModel('Model_Campaign');
        $this->email_obj = getLibClass('itrialEmail');
        $this->StaruserReport = getModel('Model_StaruserReport');
        $this->StaruserUser = getModel('Model_StaruserUser');
        $this->StaruserHiliteuser = getModel('Model_StaruserHiliteuser');
        $this->BlogCategory = getModel('Model_BlogCategory');
        $this->FG = getModel('Model_FG');
        $this->ToFgBlog = getModel('Model_ToFgBlog');

        require_once(LIB_PATH . '/Common/HTMLPurifier/HTMLPurifier.standalone.php');

        parent::cgiapp_prerun();
    }

    function action_testBlogCategory() {
        $h_param = array(
            'mid' => 17181,
        );
        $data = $this->BlogCategory->getList($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';

        $h_param = array(
            'rid' => 10700,
        );
        $data = $this->BlogCategory->getCategoryByReport($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_StaruserHiliteuser() {
        $data = $this->StaruserHiliteuser->getList();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_fg_product() {
        $h_param = array();
        $h_param['pid'] = $this->get_q('pid', 0, 'int');;
        $h_param['cid'] = $this->get_q('cid', 0, 'int');
        $h_param['size'] = 10;
        $data = $this->FG->get_fg_product($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }
    
    function action_to_fg_blog() {
        $h_param = array();
        
        $data = $this->ToFgBlog->get_blog($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }
    
    function action_fg_blog() {
        $h_param = array();
        $h_param['id'] = $this->get_q('id', 0, 'int');;
        $h_param['page'] = 1;
        $h_param['size'] = 12;
        $data = $this->FG->get_fg_blog_list($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_get_fg_hilite_left_product() {

        $data = $this->FG->get_fg_hilite_left_product();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_get_fg_hilite_middle_product() {

        $data = $this->FG->get_fg_hilite_middle_product();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_fg_new_report() {

        $h_param = array();
        $h_param['page'] = 1;
        $h_param['size'] = 12;
        $data = $this->FG->get_new_fg_report($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_fg_hilite_category() {

        $data = $this->FG->get_fg_hilite_category();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }
    function action_fg_hilite_user() {

        $data = $this->FG->get_fg_hilite_user();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_fg_product_by_category() {

        $h_param = array();
        $h_param['cid'] = $this->get_q('cid', 1, 'int');
        $data = $this->FG->get_fg_product_by_category($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_fg_report() {
        $h_param = array();
        $h_param['id'] = $this->get_q('id', 9707, 'int');
        $h_param['pid'] = $this->get_q('pid', 9707, 'int');
        $data = $this->FG->get_fg_report($h_param);
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function action_StaruserUser() {
        $data = $this->StaruserUser->getList();
        echo '<pre>' . var_export($data, 1) . '</pre>';
    }

    function testupload() {
        $root = $this->param('WWW');
        $array = uploadfiles($root . '/upload/blog', "http://itrial.hk/upload/hilite/index/help/13/01/11_1852.jpg-130x130-0.jpg");
        echo '<pre>' . var_export($array, 1) . '</pre>';
        echo str_replace($root, '', $array[0]['path']);
    }

    function action_test() {

        $is_submit = $this->get_q("is_submit");
        if ($is_submit) {
            $content = $this->get_q('content');
            $ttt = $this->get_q('ttt');

            $config = HTMLPurifier_Config::createDefault();
            $config->set('HTML.TargetBlank', true);
            $config->set('HTML.Allowed', 'span[style],em,strong,img[src|align|height|width|alt|style],br,b');
//保留指定標籤，和標籤的屬性，其它全部過濾

            $HTMLPurifierObj = new HTMLPurifier($config);
            $str = $HTMLPurifierObj->purify($content);

            $sql = 'update test set  bb="' . mysql_escape_string($ttt) . '" where id=1';
            db_handle($sql);

            echo $str;
            echo htmlspecialchars($str);
        } else {
            return $this->load_tmpl("test.php");
        }
    }

    function action_trial_invitation() {
        $session = $_SESSION['num'];
        $_SESSION['num'] = $session + 1;
        sos($_SESSION['num']);
        echo $_SESSION['num'];
        db_handle('update product set click=click+1 where id=' . mysql_escape_string(1));
        return $this->load_tmpl("test1.php");
    }

    function action_detail() {
        $id = $this->get_q('id', '1', 'int');
        if (!$id)
            $id = 1;

        $data = $this->Product->getProductById($id);



        $this->tmpl_assign('data', $data);
        return $this->load_tmpl('memberList.php');
    }

    function action_getALLuser() {
        $data = $this->Product_application->getAllUser(2);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_Campaign() {
        $id = $this->get_q('id', 1, 'int');

        $data = $this->Campaign->getList($id);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getReportsList() {
        $id = $this->get_q('id', '1', 'int');
        $mid = $this->get_q('mid', '0', 'int');
        $data = $this->ProductReports->getReportsList(0, 0);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_Top5() {

        $data = $this->Top5->getList(0, 0);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getLookup() {
        $type = $this->get_q('type');
        $data = $this->Lookup->getLookup($type);
        $str = '';
        if ($data["result"]) {
            foreach ($data["result"] as $value) {
                $str .="<br>" . $value['id'] . "：" . $value['cname'];
            }
        }

        echo $str;

        exit();
    }

    function action_getReportsCommentList() {
        $id = $this->get_q('id', '1', 'int');
        $data = $this->ProductReportsComment->getReportsCommentList($id);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getEventList() {
        $type = $this->get_q('type', '0', 'int');
        $state = $this->get_q('state', '0', 'int');
        $data = $this->Event->getEventList($type, $state);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getEventById() {
        $id = $this->get_q('id', '0', 'int');
        $data = $this->Event->getEventById($id);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getMyApplicationList() {

        //$data = $this->Product_application->getMyApplicationList(1718);
        $data = $this->MemberApplication->getMyApplicationList(1718);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_getindexBanner() {

        //$data = $this->Product_application->getMyApplicationList(1718);
        $data = $this->indexBanner->getindexBanner();

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();
    }

    function action_points() {

        $is_submit = $this->get_q("is_submit");
        if ($is_submit) {

            $uid = $this->get_q("uid");
            $action = $this->get_q("action_name");
            $remark = "測試錄入";

            $result = $this->Points->points_record($uid, $action, $remark);

            echo '<pre>' . var_export($result, 1) . '</pre>';
        } else {

            $action_test = $this->Points->points_record(20030, "system_add", "系統送分", 0, 10000);

            echo '<pre>' . var_export($action_test, 1) . '</pre>';


            $action_array = $this->Points->get_points_action();

            $this->tmpl_assign('action_array', $action_array);
            return $this->load_tmpl("test_points.php");
        }
    }

    function action_searchProduct() {
        $keyword = $this->get_q('keyword');

        $data = $this->Product->getProductList(0, 0, '', 1, 10);

        $output = var_export($data, 1);
        echo '<pre>' . $output . '</pre>';
        exit();

        $str = '<table width=100% cellpadding=0 cellspacing=0 border=0 > 
<script>  
thisURL = document.URL;  
thisHREF = document.location.href;  
thisSLoc = self.location.href;  
thisDLoc = document.location;  
strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"  
document.write( strwrite );  
</script>  
thisDLoc = document.location; <BR> 
thisURL = document.URL; <BR> 
thisHREF = document.location.href; <BR> 
thisSLoc = self.location.href;<BR> 
<script>  
thisTLoc = top.location.href;  
thisPLoc = parent.document.location;  
thisTHost = top.location.hostname;  
thisHost = location.hostname;  
strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>"  
document.write( strwrite );  
</script>  
thisTLoc = top.location.href; <BR> 
thisPLoc = parent.document.location; <BR> 
thisTHost = top.location.hostname; <BR> 
thisHost = location.hostname;<BR> 
<script>  
tmpHPage = thisHREF.split( "/" );  
thisHPage = tmpHPage[ tmpHPage.length-1 ];  
tmpUPage = thisURL.split( "/" );  
thisUPage = tmpUPage[ tmpUPage.length-1 ];  
strwrite = "<tr><td valign=top>thisHPage: </td><td>[" + thisHPage + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisUPage: </td><td>[" + thisUPage + "]</td></tr>"  
document.write( strwrite );  
</script><tr><td>';

        echo $str;
    }

    function action_getIMoreNews() {


        echo getAge('1977-12-16');
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new Product();
$webapp->run();
?>